04. Access Specifiers
Accessmodifiers
## Inherited Access Specifiers
Just as access specifiers (i.e.
public
,
protected
, and
private
) define which class members
users
can access, the same access modifiers also define which class members
users of a derived classes
can access.
Public inheritance: the public and protected members of the base class listed after the specifier keep their member access in the derived class
Protected inheritance: the public and protected members of the base class listed after the specifier are protected members of the derived class
Private inheritance: the public and protected members of the base class listed after the specifier are private members of the derived class
Source: C++ reference
In the exercise below, you'll experiment with access modifiers.
Instructions
-
Update the derived classes so that one has
protectedinheritance and one hasprivateinheritance. -
Try to access a
protectedmember frommain(). Is it possible? -
Try to access a
privatemember frommain(). Is it possible? -
Try to access a member of the base class from within the derived class that has
protectedinheritance. Is it possible? -
Try to access a member of the base class from within the derived class that has
privateinheritance. Is it possible?
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: jupyter
- Opened files (when workspace is loaded): n/a